/*
 * Copyright (C) 2015 kmy-framework-base Project
 *               Author: Administrator
 *               Date: 2015年11月4日
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zmq.ha.client.facotry;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 
 * Name: NameThreadFacotry.java
 * ProjectName: [kmy-framework-base]
 * Package: [com.kmy.framework.rabbitmq.recover.facotry.NameThreadFacotry.java]
 * Description: 可生成自命名线程的工厂类  
 * 
 * @since JDK1.7
 * @see
 *
 * Author: @author: Chris
 * Date: 2015年11月4日 下午4:39:03
 *
 * Update-User: @author
 * Update-Time:
 * Update-Remark:
 * 
 * Check-User:
 * Check-Time:
 * Check-Remark:
 * 
 * Company: kmy
 * Copyright: kmy
 */
public class NameThreadFacotry implements ThreadFactory {
	
	private final String threadName;
	
	private final AtomicInteger threadCount = new AtomicInteger(0);

	public NameThreadFacotry(String threadName) {
		super();
		this.threadName = threadName;
	}
	
	@Override
	public Thread newThread(Runnable r) {
		
		return new Thread(r,String.format(threadName+"-%s", threadCount.getAndIncrement()));
	}
}
